import numpy as np
import matplotlib.pyplot as plt

size = 5
a = np.random.random(size)
b = np.random.random(size)
c = np.random.random(size)
d = np.random.random(size)
x = np.arange(size)

total_width, n = 0.8, 3     # 有多少个类型，只需更改n即可
width = total_width / n
x = x - (total_width - width) / 2


ax=plt.gca()


ax.spines['top'].set_visible(False) #去掉上边框
ax.spines['right'].set_visible(False) #去掉右边框
ax.spines['left'].set_visible(False) #去掉右边框

ax.spines['bottom'].set_color('blue')
# ax.spines['left'].set_color('#a597b9')

#设置Y坐标轴上(水平方向)的栅格线
ax.yaxis.grid(color='r', linestyle='--', linewidth=1,alpha=0.1)

plt.bar(x, a,  width=width, label='a')
plt.bar(x + width+0.01, b, width=width, label='b')
plt.bar(x + 2 * width+0.02, c, width=width, label='c')
plt.legend()

plt.savefig("123.png",dpi=300)
plt.show()